document.getElementById("btn").onclick = function() {
	const textarea = document.getElementById('text');

	if (textarea.value) {
		const trimed = textarea.value.replace(/\s/g, "");
		textarea.value = trimed;
		const input = document.createElement('input');
		document.body.appendChild(input);
		input.setAttribute('value', trimed);
		input.select();
		if (document.execCommand('copy')) {
			document.execCommand('copy');
			showInfo('复制成功', 3000, 'green')
		} else {
			showInfo('复制失败', 3000, 'red')
		}
		document.body.removeChild(input);
	}
}

function showInfo(text, time, color) {
	const infoDiv = document.getElementById('info');
	infoDiv.innerText = text
	infoDiv.style.color = color
	setTimeout(function() {
		infoDiv.innerText = ''
	}, time)
}
